#include	"WindowsException.h"

WindowsException::WindowsException(DWORD code)
	:	std::exception()
	,	m_code(code)
	,	m_message()
{
	LPTSTR msgBuffer = 0;
	if(0 != ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, m_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPSTR>(&msgBuffer), 0, 0))
	{
		m_message = msgBuffer;
		::LocalFree(msgBuffer);
	}
}

const char * WindowsException::what() const
{
	return m_message.c_str();
}

DWORD WindowsException::error_code() const
{
	return m_code;
}

